<?php
class Filter {
    public static function work($t,$name, $f, $default='0'){
        $type = [
            0 => INPUT_GET,
            1 => INPUT_POST,
            2 => INPUT_COOKIE,
            3 => INPUT_SERVER,
            4 => INPUT_ENV,
        ];
        $filter = [
            0 => FILTER_SANITIZE_ENCODED,
            1 => FILTER_SANITIZE_MAGIC_QUOTES,
            2 => FILTER_SANITIZE_NUMBER_FLOAT,
            3 => FILTER_SANITIZE_NUMBER_INT,
            4 => FILTER_SANITIZE_SPECIAL_CHARS,
            5 => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
            6 => FILTER_SANITIZE_STRING,
            7 => FILTER_SANITIZE_STRIPPED,
            8 => FILTER_SANITIZE_URL,
            9 => FILTER_UNSAFE_RAW,
        ];
        $result = filter_input($type[$t],$name,$filter[$f]);
        if(empty($result) || $result == null){
            return $default;
        }else{
            return $result;
        }
    }
    public static function val($value, $f, $default='0',$options=null){
        $result = null;
        $filter = [
            0 => FILTER_SANITIZE_ENCODED,
            1 => FILTER_SANITIZE_MAGIC_QUOTES,
            2 => FILTER_SANITIZE_NUMBER_FLOAT,
            3 => FILTER_SANITIZE_NUMBER_INT,
            4 => FILTER_SANITIZE_SPECIAL_CHARS,
            5 => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
            6 => FILTER_SANITIZE_STRING,
            7 => FILTER_SANITIZE_STRIPPED,
            8 => FILTER_SANITIZE_URL,
            9 => FILTER_UNSAFE_RAW,
        ];
        if($options === null){
            $result = filter_var($value,$filter[$f]);
        }else{
            $result = filter_var($value,$filter[$f],$options);
        }
        return result;
    }
}